package com.jingdianjichi.oss.config;

import com.jingdianjichi.oss.adapter.AliStorageAdapter;
import com.jingdianjichi.oss.adapter.MinioStorageAdapter;
import com.jingdianjichi.oss.adapter.StorageAdapter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
    * ClassName :StorageConfig
    * Package :com.jingdianjichi.oss.config
    * Desciption :
    *@Author :
    *@Create : 23:22
    *@Version :1.0
*/
@Configuration
@RefreshScope
public class StorageConfig {
    @Value("${storage.service.type}")
    private String storageType;


    @Bean
    @RefreshScope
    public StorageAdapter storageAdapter(){
        if("minio".equals(storageType)){
            return new MinioStorageAdapter();
        }
        else if("aliyun".equals(storageType)){
            return new AliStorageAdapter();
        }
        else{
            throw new IllegalArgumentException("未找到对应的文件处理器");
        }
    }
}
